//
//  UIView+Helper.m
//  NewPor
//
//  Created by 中昊科技 on 15/4/27.
//  Copyright (c) 2015年 中昊科技. All rights reserved.
//

#import "UIView+Helper.h"

@implementation UIView (Helper)

-(CGFloat)endPointX
{
    return self.frame.origin.x+self.frame.size.width;
}

-(CGFloat)endPointY
{
    return self.frame.origin.y+self.frame.size.height;
}
-(CGFloat)startPointX
{
    return self.frame.origin.x;
}
-(CGFloat)startPointY
{
    return self.frame.origin.y;
}

+ (instancetype)viewOfOnePixelHeightWithFrame:(CGRect)frame {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 1.0/[UIScreen mainScreen].scale)];
    //    view.backgroundColor = UIColorFromRGBA(0xd6d7dc, 1);
    return view;
}

+ (instancetype)viewOfOnePixelWidthWithFrame:(CGRect)frame {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, 1.0/[UIScreen mainScreen].scale, frame.size.height)];
    //    view.backgroundColor = UIColorFromRGBA(0xd6d7dc, 1);
    return view;
}

- (void)setBorderWithTop:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right backgroundColor:(nullable UIColor *)backgroundColor {
    UIColor *color = nil;
    if (backgroundColor == nil) {
        //        color = UIColorFromRGBA(0xd6d7dc, 1);
        color = [UIColor grayColor];
    }else {
        color = backgroundColor;
    }
    CGFloat width = 1.0/[UIScreen mainScreen].scale;
    
    if (top) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = color;
        [self addSubview:view];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left);
            make.right.equalTo(self.mas_right);
            make.top.equalTo(self.mas_top).offset(width);
            make.height.mas_equalTo(width);
        }];
        
    }
    if (left) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = color;
        [self addSubview:view];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top);
            make.left.equalTo(self.mas_left).offset(width);
            make.width.mas_equalTo(width);
            make.bottom.equalTo(self.mas_bottom);
        }];
    }
    if (bottom) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = color;
        [self addSubview:view];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left);
            make.right.equalTo(self.mas_right);
            make.bottom.equalTo(self.mas_bottom).offset(width);
            make.height.mas_equalTo(width);
        }];
    }
    if (right) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = color;
        [self addSubview:view];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top);
            make.right.equalTo(self.mas_right).offset(width);
            make.bottom.equalTo(self.mas_bottom);
            make.width.mas_equalTo(width);
        }];
        
    }
}

@end



@implementation UITableView (Helper)


-(void)setExtraCellLineHidden
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [self setTableFooterView:view];
}


@end
